class ValidWordAbbr(object):

    def __init__(self, dictionary):
        """
        :type dictionary: List[str]
        """
        self.d = {}

        for item in dictionary:
            s = self.suoxie(item)
            if s in self.d:
                self.d[s].add(item)
            else:
                self.d[s] = {item}

    def suoxie(self, word):
        if len(word) <= 2:
            return word
        else:
            return word[0] + str(len(word) - 2) + word[-1]

    def isUnique(self, word):
        """
        :type word: str
        :rtype: bool
        """
        s = self.suoxie(word)
        if s not in self.d:
            return True
        else:
            if len(self.d[s]) == 1 and word in self.d[s]:
                return True
            else:
                return False
